<?php

namespace app\data\controller;
use think\admin\Controller;
use think\admin\helper\QueryHelper;
use app\data\model\DataMember;
/**
 * 用户管理
 * @class Member
 * @package app\data\controller
 */
class Member extends Controller
{
    /**
     * 用户管理
     * @menu true
     * @auth true
     */
    public function index()
    {
        DataMember::mQuery()->layTable(function () {
            $this->title = '用户管理';
        }, function (QueryHelper $query) {
            $query->where(['is_deleted' => 0]);
            $query->withCount(['cats','devices']);
            // 数据列表搜索过滤
            $query->equal('status')->dateBetween('create_at#create_at');
            $query->like('nickname,mobile')->order('create_at desc');
        });
    }

    /**
     * 修改用户状态
     * @auth true
     */
    public function state()
    {
        $this->_checkInput();
        DataMember::mSave($this->_vali([
            'identity.in:0,1'  => '状态值范围异常！',
            'identity.require' => '状态值不能为空！',
        ]));
    }
    /**
     * 检查输入变量
     */
    private function _checkInput()
    {
        if (in_array('10000', str2arr(input('id', '')))) {
            $this->error('系统超级账号禁止删除！');
        }
    }
}
